package actions;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import dao.inter.MaintowerDeformation;
import net.sf.json.JSONObject;
import utils.Check;
import utils.JSONResponse;
import utils.Pub;

/*
 * 主塔变形
 */
public class MaintowerDeformationAction extends CMActionSupport {

	private Logger logger = LogManager.getLogger(MaintowerDeformationAction.class);
	private MaintowerDeformation testDao;
	private String bridgeType = Pub.BRIDGE_XIASHA;
	private String beginDate = "";
	private String endDate = "";
	private String sensor = "";
	private String direction = "";
	private String red = "";
	private String yellow = "";
	private String warning = "";

	public void getMaintowerDeformationData() throws Exception {
		this.logger.error("\nbridgeType:" + this.bridgeType + "\nbeginDate:" + this.beginDate + "\nendDate:"
				+ this.endDate + "\nsensor:" + this.sensor + "\ndirection:" + this.direction + "\nred:" + this.red
				+ "\nyellow:" + this.yellow);
		if (this.hasFieldErrors()) {
			logger.error("参数出错！！！");
			return;
		}
		JSONObject jsonData = this.testDao.getJsonResultByDateAndSersors(red, yellow, bridgeType, beginDate, endDate,
				sensor);
		if (!jsonData.getBoolean(Pub.STATUS)) {
			jsonData.put(Pub.STATUS, false);
			jsonData.put(Pub.MESSAGE, jsonData.getString(Pub.MESSAGE));
		} else {
			jsonData.put(Pub.STATUS, true);
			jsonData.get(Pub.DATA);
		}
		logger.debug("json is " + jsonData.toString());
		JSONResponse.returnJsonToResponse(jsonData);

	}

	@Override
	public void validate() {
		super.validate();
		JSONObject json = Check.check(this.beginDate, this.endDate, sensor);
		if (json.containsKey("name")) {
			this.addFieldError(json.getString("name"), json.getString(Pub.MESSAGE));
		}
	}

	public void setWarning(String warning) {
		this.warning = warning;
	}

	public void setBridgeType(String bridgeType) {
		this.bridgeType = bridgeType;
	}

	public void setSensor(String sensor) {
		this.sensor = sensor;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public void setRed(String red) {
		this.red = red;
	}

	public void setYellow(String yellow) {
		this.yellow = yellow;
	}

	public MaintowerDeformation getMaintowerDeformation() {
		return testDao;
	}

	public void setMaintowerDeformation(MaintowerDeformation testDao) {
		this.testDao = testDao;
	}
}
